const install=function(Vue){
    Vue.prototype.httpurl=function(url,fromwho){
        var sid=sessionStorage.getItem('sid')
        switch (fromwho){
            case 'ch':
                return  "http://card.adouyun.com/CloudCard/"+url+".shtml?sessionid="+sid;
                break;
            default:
                return  "http://card.adouyun.com/CloudCard/"+url+".shtml?sessionid="+sid;
                break;
        }
    }
    Vue.prototype.catchurl=function(url){
        if(url.indexOf('http')==-1){
            return  "http://card.adouyun.com/CloudCard/"+url;
        }
        return url
    }
    Vue.prototype.getRootPath=function(url){
        //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
        var curWwwPath=window.document.location.href;
        //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
        var pathName=window.document.location.pathname;
        var pos=curWwwPath.indexOf(pathName);
        //获取主机地址，如： http://localhost:8083
        var localhostPaht=curWwwPath.substring(0,pos);
        //获取带"/"的项目名，如：/uimcardprj
        var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
        return(localhostPaht+projectName);
    }
    Vue.prototype.timeBetween=function (time){
        var nms=new Date().getTime();
        var bms=nms-time;
        var rtime='';
        var month= Math.floor(bms / (1000 * 60 * 60 * 24 * 30));
        var d= Math.floor(bms / (1000 * 60 * 60 * 24));
        var h= Math.floor(bms / (1000 * 60 * 60));
        var m = Math.floor(bms / (1000 * 60));
        var s = Math.ceil(bms / (1000));
        if(month>0){rtime=`${month}月前`;}else{
            if(d>0){rtime=`${d}天前`;}else{
                if(h>0){rtime=`${h}小时前`;}else{
                    if(m>0){rtime=`${m}分钟前`;    }else{
                        rtime=`${s}秒前`;
                    }
                }
            }
        }
        if(month>12){
            rtime='1年前及更早';
        }
        return rtime;
    }
    Vue.prototype.timeDate=function(time,type){
        var date = new Date(time); //获取一个时间对象
        var year=date.getFullYear();  // 获取完整的年份(4位,1970)
        var month=date.getMonth()+1;  // 获取月份(0-11,0代表1月,用的时候记得加上1)
        var day=date.getDate();  // 获取日(1-31)
        var hour=date.getHours();  // 获取小时数(0-23)
        if(hour<10){
            hour='0'+hour
        }
        var min=date.getMinutes();  // 获取分钟数(0-59)
        if(min<10){
            min='0'+min
        }
        var sec=date.getSeconds();  // 获取秒数(0-59)
        if(sec<10){
            sec='0'+sec
        }
        var ms=date.getTime();  // 获取时间(从1970.1.1开始的毫秒数)
        switch (type){
        	case 1:
            	var date_ymd=year + "-" + month + "-" + day
                return date_ymd
        		break;
            case 2:
                var date_hms=year + "-" + month + "-" + day+'  '+hour+":"+min+":"+sec
                return date_hms
                break;
            case 3:
                var date_ymd_ch=year + "年" + month + "月" + day + "日"
                return date_ymd_ch
                break;
        	default:
        	    var date_ymd=year + "-" + month + "-" + day
                return date_ymd
        		break;
        }
    }
}
export default install
